(()=> {
	let ele = {};
	ele.zhaonum1 = $('#zhaonum1');
	ele.zhaonum2 = $('#zhaonum2');
	ele.yinbi = $('#yinbi');
	ele.jinbi = $('#jinbi');
	ele.listBox1 = $('#listBox1');
	ele.listBox2 = $('#listBox2');
	ele.more = $('#more');
	ele.more2 = $('#more2');
	ele.empty = $('#empty');
	ele.empty2 = $('#empty2');
	ele.zhao_rc1 = $('#zhao_rc1');
	ele.zhao_rc2 = $('#zhao_rc2');
	ele.zhao_lt = $('#zhao_lt');
	ele.modal_tips2 = $('#modal-tips2');
	ele.close_tips2 = $('#close-tips2');
	ele.recievenum = $('#recievenum');
	ele.recieveimg = $('#recieveimg');
	ele.tipsbtn = $('#tipsbtn');
	ele.mingzi = $('#mingzi');
	ele.zanwei = $('.zanwei');
	ele.mingzi = $('#mingzi');
	ele.recieveimg2 = $('#recieveimg2');
	ele.floimg = $('#floimg');
	ele.mkad4 = $('#mkad4');
	
	
	let is_guangg = '';
	let ad_max_num = '';
	let ad_see_num = '';
	
	let ggcishu = '';
	
	 adv_index();
	// 广告免费
	function adv_index() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.ADVERTISEMENT_ADV_INDEX,
			method: 'GET',
			header: {
				'Authorization': token,
			},
			success: res => {
				if (res.code == 1) {
					ad_max_num = res.data.max_num;
					ad_see_num = res.data.see_num;
					ele.mkad4.innerHTML = '<button>免看广告 <span class="fontgreen">'+res.data.lose_num+'/'+res.data.all_num+'</span></button>'
					if(res.data.lose_num >= res.data.all_num) {
						ele.mkad4.innerHTML = '<button>免看广告 <span class="fontred">'+res.data.lose_num+'/'+res.data.all_num+'</span></button>'
					}
					recruieIndex()
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	
	// 广告领取免费
	function adv_index_reward(id) {
		let token = getCookie("token");
		ajax({
			url: API_PATH.ADVERTISEMENT_GET_RECORD,
			method: 'GET',
			header: {
				'Authorization': token,
			},
			data: {
				type: id
			},
			success: res => {
				if (res.code == 1) {
					openTips(res.msg);
					adv_index();
					recruieIndex();
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	ele.mkad4.onclick = ()=> {
		adv_index_reward(4)
	}
	
	// 广告加速器
	function addTime() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.ADVEERTISEMENT_ADD_TIME,
			method: 'get',
			header: {
				'Authorization': token,
			},
	
			success: res => {
				if (res.code == 1) {
					
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	
	//关闭 恭喜获得
	ele.close_tips2.onclick = () => {
		closeMdl(ele.modal_tips2);
	}
	ele.tipsbtn.onclick = () => {
		closeMdl(ele.modal_tips2);
	}
	
	let uid = getCookie('userid');
	let device = getClientType();
	
	// 加载广告 安卓
	function loadAd() {
		window.android.loadPlayRewardVideo('1661241482792681560',uid,'4', "callBack3");
	}
	
	
	// 激励视频回调：
	window.callBack3 = function(params) {
		if (params.code == 2) {
			// openTips('奖励已送达')
			//奖励达成回调
			setTimeout(()=> {
				location.reload(true)
			},500)
		}
		if (params.code == 1) {
			setTimeout(()=> {
				location.reload(true)
			},500)
			//展现回调
		}
		if (params.code == 0) {
			// alert(params)
			alert('广告拉取错误',params.msg);
			//错误回调：错误信息：params.msg
		}
	}
	
	function loadPlayRewardVideo(extradata)
	{
	    //调用激励视频广告方法
		extradata = extradata.toString()
		uid = uid.toString()
		window.webkit.messageHandlers.loadPlayRewardVideo.postMessage({userId:uid,extraData:extradata});
	    // window.webkit.messageHandlers.loadPlayRewardVideo.postMessage("12345");
	}
	
	
	function onRewardLoadFailed()
	{
	    //激励视频失败回调
	    // alert("激励视频请求失败");
	}
	function onRewardVideoVerify()
	{
	    //激励视频奖励达成回调
	   // alert("激励视频奖励达成了");
	}
	function onRewardVideoClose()
	{
	    //激励视频关闭回调
	    // alert("激励视频关闭了");
	}
	
	recruieIndex();
	function recruieIndex() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.RECRUIT_INDEX,
			method: 'GET',
			header: {
				'Authorization': token,
			},
			success: res => {
				if (res.code == 1) {
					ggcishu = res.data.data.rc.use_sp_num
					ele.zhaonum1.innerHTML = '每日可招聘次数(<span>'+res.data.data.rc.silver_num+'</span>/'+res.data.rc_list.max_num+')'
					ele.zhaonum2.innerHTML = '看广告招聘剩余次数(<span>'+res.data.data.rc.use_sp_num+'</span>/'+res.data.rc_list.num+')'
					// console.log(res.data.data.rc.use_sp_num,res.data.data.rc.sp_num);
					if(res.data.data.rc.sp_num == 0) {
						ele.zhao_rc2.innerHTML = '<img src="http://img.qxgs.cc/tiantianlaishouzu/img/mine/action.png" alt="">免费招聘'
						// console.log(ad_see_num,ad_max_num);
						ele.zhao_rc2.onclick = ()=> {
							adv_index();
							if(ad_see_num >= ad_max_num || ggcishu <= 0) {
								openTips('今日视频次数已达上限，请明日再来')
							} else {
								if(is_guangg == 0) {
									is_guangg = 1;
									setTimeout(()=> {
										is_guangg = 0
									},2000)
									if(device == 'ios') {
										loadPlayRewardVideo(4)
									} else if(device == 'android') {
										loadAd(4);
									} else {
										openTips('请下载安卓最新版体验')
									}
								}
								addTime()
							}
						}
					} else {
						ele.zhao_rc2.innerHTML = '免费招聘'
						ele.zhao_rc2.onclick = ()=> {
							recruitGetIndex(2); // 免费招聘
						}
					}
					ele.yinbi.innerHTML = res.data.agent.hammer + res.data.agent.unit + '/' + res.data.data.rc.money;
					ele.jinbi.innerHTML = res.data.agent.gold + '/' +res.data.data.lt.money ;
					drawList_rc(res.data.data.rc.record);
					drawList_lt(res.data.data.lt.record);
				} else openTips(res.msg || '未知错误');
			}
		});
	}
		
	function drawList_rc(_data) {
		let html = '';
		let pj_type = '';
		for(let i = 0; i < _data.length; i++) {
			// console.log(_data[i].hammer);	
			pj_type = _data[i].info.hammer == 6 ? 'itemred' :  _data[i].info.hammer == 2 ? 'itemgreen' : _data[i].info.hammer == 3 ? 'itemblue' :  _data[i].info.hammer == 4 ? 'itempurple' :  _data[i].info.hammer == 5 ? 'itemorange' : '';
			html += '<div class="list">'
						+'<p>'+_data[i].agent_info.nick_name+'</p>'
						+'<div class="listin">'
							+'<img class="leftimg '+pj_type+'" src="'+IMG_DOMAIN+_data[i].info.logo+'" alt="">'
							+'<p>'+_data[i].info.name+'</p>'
						+'</div>'
					+'</div>'
		}
		ele.listBox1.innerHTML = html;
	}
	
	function drawList_lt(_data) {
		// console.log(_data);
		let html = '';
		let pj_type = '';
		for(let i = 0; i < _data.length; i++) {
			// console.log(_data[i].hammer);
			pj_type = _data[i].info.hammer == 6 ? 'itemred' :  _data[i].info.hammer == 2 ? 'itemgreen' : _data[i].info.hammer == 3 ? 'itemblue' :  _data[i].info.hammer == 4 ? 'itempurple' :  _data[i].info.hammer == 5 ? 'itemorange' : '';
			html += '<div class="list">'
						+'<p>'+_data[i].agent_info.nick_name+'</p>'
						+'<div class="listin">'
							+'<img class="leftimg '+pj_type+'"  src="'+IMG_DOMAIN+_data[i].info.logo+'" alt="">'
							+'<p>'+_data[i].info.name+'</p>'
						+'</div>'
					+'</div>'
		}
		ele.listBox2.innerHTML = html;
	}
	
	ele.zhao_rc1.onclick = ()=> {
		recruitGetIndex(3);
	}
	
	ele.zhao_lt.onclick = ()=> {
		getLtRecruit();
	}
	// 人才直聘招募
	function recruitGetIndex(type) {
		let token = getCookie("token");
		ajax({
			url: API_PATH.RECRUIT_GET_INDEX,
			method: 'POST',
			header: {
				'Authorization': token,
			},
			data: {
				type: type
			},
			success: res => {
				if (res.code == 1) {
					// openTips(res.msg);
					// if(res.data.info.b_type == 1) {
					// 	ele.mingzi.style.display = 'none'
					// 	ele.recievenum.style.display = 'block';
					// 	ele.recieveimg.src = 'http://img.qxgs.cc/tiantianlaishouzu/img/home/yinbi3.png'
					// 	ele.recievenum.innerHTML = '<span>'+res.data.num + res.data.info.name+'</span>'
					// 	openMdl(ele.modal_tips2);
					// }else if(res.data.info.b_type == 2) {
					// 	ele.mingzi.style.display = 'none';
					// 	ele.recievenum.style.display = 'block';
					// 	ele.recieveimg.src = 'http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi3.png'
					// 	ele.recievenum.innerHTML = '<span>'+res.data.num + res.data.info.name+'</span>'
					// 	openMdl(ele.modal_tips2);
					// } else {
					// 	let pj_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'flexcolomimg1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'flexcolomimg2' :  res.data.info.hammer == 5 ? 'flexcolomimg3' : '';
					// 	ele.mingzi.style.display = 'block'
					// 	ele.recieveimg.src = IMG_DOMAIN + res.data.info.logo
					// 	ele.recieveimg.className = pj_type;
					// 	ele.mingzi.innerHTML =' <p>'+res.data.info.name+'</p><span>'+res.data.info.name+'</span>'
					// 	ele.recievenum.style.display = 'none';
					// 	openMdl(ele.modal_tips2);
					// }
					
					ele.recieveimg.src = res.data.info.b_type == 1 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/home/yinbi3.png' : res.data.info.b_type == 2 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi3.png' :  res.data.info.b_type == 3 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/public/cuizi.png' : IMG_DOMAIN + res.data.info.logo
					if(res.data.info.b_type == 1 || res.data.info.b_type == 2) {
						ele.floimg.style.display = 'none'
						ele.recievenum.style.display = 'block'
						ele.recieveimg.style.display = 'block'
						ele.recievenum.innerHTML = res.data.num + res.data.info.name;
					} else {
						ele.floimg.style.display = 'none'
						ele.recievenum.style.display = 'block'
						ele.recieveimg.style.display = 'block'
						ele.recievenum.innerHTML = parseInt(res.data.num) + res.data.info.name;
					}
					if(res.data.info.is_default == 3) {
						let pj_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'flexcolog1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'flexcolog2' :  res.data.info.hammer == 5 ? 'flexcolog3' : '';
						let mz_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'mingzi1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'mingzi' :  res.data.info.hammer == 5 ? 'mingzi' : '';
						ele.floimg.style.display = 'block'
						ele.recievenum.style.display = 'none'
						ele.recieveimg.style.display = 'none'
						ele.recieveimg2.className = pj_type;
						ele.recieveimg2.src = IMG_DOMAIN + res.data.info.rc_info.logo
						ele.mingzi.innerHTML = '<p>'+res.data.info.rc_info.class.jz_name+'</p><span class="'+mz_type+'">'+res.data.info.rc_info.name+'</span>'
					}
					openMdl(ele.modal_tips2);
					recruieIndex();
				} else openTips(res.msg || '未知错误');
			}
		});
	}
	
	// 猎头直聘招募
	function getLtRecruit() {
		let token = getCookie("token");
		ajax({
			url: API_PATH.GET_LT_RECRUIT,
			method: 'POST',
			header: {
				'Authorization': token,
			},
			success: res => {
				if (res.code == 1) {
					// openTips(res.msg);
					// if(res.data.info.b_type == 1) {
					// 	ele.mingzi.style.display = 'none'
					// 	ele.recievenum.style.display = 'block';
					// 	ele.recieveimg.src = 'http://img.qxgs.cc/tiantianlaishouzu/img/home/yinbi3.png'
					// 	ele.recievenum.innerHTML = '<span>'+res.data.num + res.data.info.name+'</span>'
					// 	openMdl(ele.modal_tips2);
					// }else if(res.data.info.b_type == 2) {
					// 	ele.mingzi.style.display = 'none';
					// 	ele.recievenum.style.display = 'block';
					// 	ele.recieveimg.src = 'http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi3.png'
					// 	ele.recievenum.innerHTML = '<span>'+res.data.num + res.data.info.name+'</span>'
					// 	openMdl(ele.modal_tips2);
					// } else {
					// 	let pj_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'flexcolomimg1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'flexcolomimg2' :  res.data.info.hammer == 5 ? 'flexcolomimg3' : '';
					// 	ele.mingzi.style.display = 'block'
					// 	ele.recieveimg.src = IMG_DOMAIN + res.data.info.logo
					// 	ele.recieveimg.className = pj_type;
					// 	ele.mingzi.innerHTML =' <p>'+res.data.info.name+'</p><span>'+res.data.info.name+'</span>'
					// 	ele.recievenum.style.display = 'none';
					// 	openMdl(ele.modal_tips2);
					// }
					ele.recieveimg.src = res.data.info.b_type == 1 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/home/yinbi3.png' : res.data.info.b_type == 2 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/home/jinbi3.png' :  res.data.info.b_type == 3 ? 'http://img.qxgs.cc/tiantianlaishouzu/img/public/cuizi.png' : IMG_DOMAIN + res.data.info.logo
					if(res.data.info.b_type == 1 || res.data.info.b_type == 2) {
						ele.recievenum.innerHTML = '<span>' + res.data.num + res.data.info.name + '</span>';
					} else {
						ele.recievenum.innerHTML = '<span>' + parseInt(res.data.num) + res.data.info.name + '</span>';
					}
					if(res.data.info.is_default == 3) {
						let pj_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'flexcolog1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'flexcolog2' :  res.data.info.hammer == 5 ? 'flexcolog3' : '';
						let mz_type = res.data.info.hammer == 6 ? 'itemred' :  res.data.info.hammer == 2 ? 'mingzi1' : res.data.info.hammer == 3 ? 'itemblue' :  res.data.info.hammer == 4 ? 'mingzi2' :  res.data.info.hammer == 5 ? 'mingzi3' : '';ele.floimg.style.display = 'block'
						ele.recievenum.style.display = 'none'
						ele.recieveimg.style.display = 'none'
						ele.recieveimg2.className = pj_type;
						ele.recieveimg2.src = IMG_DOMAIN + res.data.info.rc_info.logo
						ele.mingzi.innerHTML = '<p>'+res.data.info.rc_info.class.jz_name+'</p><span class="'+mz_type+'">'+res.data.info.rc_info.name+'</span>'
					}
					openMdl(ele.modal_tips2);
					recruieIndex();
				} else openTips(res.msg || '未知错误');
			}
		});
	}
})()